home *** CD-ROM | disk | FTP | other *** search
- /*________________________________________________________
-
- File: Extension.c
-
- C code for a printing extension.
-
- Dave Hersey
- Apple Developer Technical Support
-
- Modified By Dave MacLachlan
-
- 12/01/92 - dmh - Created.
- 4/26/93 - dmh - Updated to use recommended approach
- to global data initialization.
- 9/05/93 - dmh - Updated for b2.
- - Fixed minor problem with highlighting
- of editText panel items.
- - Switched to Exception.h assertion stuff
- for error checking.
- 12/18/93 - dmh - Updated for b3.
- 3/22/94 - dmh - Updated for b4.
- 1/05/96 - dim - ported over to Metrowerks Codewarrior 7
- (Note: all functions are in the Mark menu.)
-
- __________________________________________________________*/
-
- #include "Extension.h"
-
-
- asm void __Startup__()
- {
-
- DC.L 0 ; //Reserved for owner count.
-
- JMP NewInitialize ; //(offset = 4)
- JMP NewShutDown ; //(offset = 8)
- JMP NewJobPrintDialog ; //(offset = 12)
- JMP NewHandlePanelEvent ; //(offset = 16)
- JMP NewSpoolPage ; //(offset = 20)
- RTS ;
- }
- /*******************************************************************
- InitGlobalData is used to initialize any global data we need to
- in our initialize message override. It's critical that you do
- things this way, rather than access the data in the same scope
- that you call NewMessageGlobals. Otherwise, some compilers
- will give you code that references an invalid A5 world.
-
- ********************************************************************/
-
- OSErr InitGlobalData()
- {
- // Initialize any global data here.
-
- return noErr;
- }
-
-
- /*******************************************************************
- NewInitialize is our override for the GXInitialize message. In
- here, you shouldn't initialize anything directly-- call
- InitGlobalData for that. Once you create the A5 world with
- NewMessageGlobals, you can access your global data just like
- you were an application. Whenever you're called, your global
- data will be valid.
-
- ********************************************************************/
-
- OSErr NewInitialize()
- {
- OSErr err;
-
- // Create an A5 world, and initialize our global data.
-
- err = NewMessageGlobals(A5Size(), A5Init);
-
- if (!err) err = InitGlobalData();
-
- return err;
- }
-
-
- /*******************************************************************
- NewShutDown is our override for the GXShutDown message. We
- simply throw away our A5 world which we created in our
- GXInitialize message override, NewInitialize.
-
- ********************************************************************/
-
- OSErr NewShutDown()
- {
- DisposeMessageGlobals();
- return noErr;
- }
-
-
- /*******************************************************************
- NewSpoolPage is our override for the GXSpoolPage message. We
- check to see if we're enabled, and if so, give a SysBeep before
- forwarding.
-
- ********************************************************************/
-
- OSErr NewSpoolPage(gxSpoolFile spFile, gxFormat aFormat, gxShape pgShape)
- {
- OSErr err;
- ExtensionCollection extCollect;
-
- // Try to retrieve our collection item. If we can't find it, we'll
- // act as if the user had us turned off or on (as determined by
- // kDefaultSetting).
-
- err = GetJobCollectionItem(&extCollect, nil, kExtensionCollectionType,
- gxPrintingTagID);
-
- if (err)
- {
- extCollect.extTurnedOn = kDefaultSetting;
- err = noErr;
- }
-
-
- // If we're turned on, beep so we know we've been here, then forward
- // this message down the chain.
-
- if (extCollect.extTurnedOn)
- SysBeep(3);
-
- err = Forward_GXSpoolPage(spFile, aFormat, pgShape);
-
- return err;
- }
-
-
- /*******************************************************************
- NewJobPrintDialog is our override for GXJobPrintDialog. All we
- do is set up our panel and then forward the message.
-
- ********************************************************************/
-
- OSErr NewJobPrintDialog(gxDialogResult *dlogResult)
- {
- OSErr err;
-
- err = SetUpPrintPanel();
-
- if (!err)
- err = Forward_GXJobPrintDialog(dlogResult);
-
- return err;
- }
-
-
- /*******************************************************************
- NewHandlePanelEvent is our override for GXHandlePanelEvent. If
- the event is one of ours, we handle it. Otherwise, we just
- forward it down the chain.
-
- ********************************************************************/
-
- OSErr NewHandlePanelEvent(gxPanelInfoRecord *panelInfo, gxPanelResult *panelResult)
- {
- OSErr err = noErr;
- GrafPtr oldPort;
- DialogPtr pDlg;
- EventRecord tempEvent;
- Str255 theItem,theAction;
- // Get a pointer to the dialog, save our current grafPort,
- // and set us to the dialog's port.
-
- pDlg = panelInfo->pDlg;
- GetPort(&oldPort);
- SetPort(pDlg);
- *panelResult = gxPanelNoResult;
- switch (panelInfo->panelEvt) // Handle any of these events as need be.
- {
- case gxPanelOpenEvt: // Initialize and draw.
- break;
- case gxPanelCloseEvt: // Your panel is going away (panel switch,
- // confirm or cancel).
- break;
-
- case gxPanelHitEvt: // There's a hit in your panel.
- break;
- case gxPanelFilterEvt: // This is called to filter every event.
- break;
- case gxPanelCancelEvt: // The user has cancelled the dialog.
- break;
- case gxPanelConfirmEvt: // The user has confirmed the dialog.
- break;
- case gxPanelUserWillConfirmEvt: // user has selected confirm, time to
- break; // parse your panel interdependencies.
-
- case gxPanelDialogEvt: // Event to be handled by dialoghandler
- break; // (you get to see all events).
-
- case gxPanelOtherEvt: // osEvts, etc.
- break;
-
- // If our panel is activating/deactivating or if the focus (which
- // section of the dialog is active) has changed we need to activate
- // our editText fields appropriately.
-
- case gxPanelActivateEvt: // The dialog window has just become active.
- break;
- case gxPanelDeactivateEvt: // The dialog window is becoming inactive.
- break;
- case gxPanelIconFocusEvt: // The user is moving to the icon list.
- break;
- case gxPanelPanelFocusEvt: // The user is moving to the panel.
-
- /* Here's what you would do if you had an editText field at DITL item #5:
-
- #define d_edText 5
-
- if ((((DialogPeek) pDlg)->editField +1) == (panelInfo->itemCount +d_edText))
- {
- if (panelInfo->panelEvt == gxPanelPanelFocusEvt)
- TEActivate(((DialogPeek) pDlg)->textH);
- else
- TEDeactivate(((DialogPeek) pDlg)->textH);
- }
- */
- break;
- }
-
- // Restore the original port as we leave.
-
- SetPort(oldPort);
- return err;
- }
-
-
- /*******************************************************************
- SetUpPrintPanel sets up our print panel, adding a default
- ExtensionCollection item to the job collection. This
- collection item has the values we'll use to set up our panel's
- controls.
-
- ********************************************************************/
-
- OSErr SetUpPrintPanel()
- {
- OSErr err;
- gxPanelSetupRecord panelSetupRec;
- ExtensionCollection extConfig;
-
- // Try to find our collection item.
-
- err = GetCollectionItem(GXGetJobCollection(GXGetJob()),
- kExtensionCollectionType,
- gxPrintingTagID,
- nil,
- &extConfig);
-
-
- // If we don't have an item in the job collection yet, store our default
- // settings in it.
-
- if (err == collectionItemNotFoundErr)
- {
- extConfig.extTurnedOn = kDefaultSetting;
-
- err = AddCollectionItem(GXGetJobCollection(GXGetJob()),
- kExtensionCollectionType,
- gxPrintingTagID,
- sizeof(ExtensionCollection),
- &extConfig);
-
- nrequire(err, HaveCollectionMgrError);
- }
-
-
- // Now, set up the panel.
-
- panelSetupRec.panelResId = r_ExtensionPanel; // which panel resource?
- panelSetupRec.resourceRefNum = GXGetMessageHandlerResFile(); // where is it?
- panelSetupRec.refCon = 0; // we don't use this.
- panelSetupRec.panelKind = gxExtensionPanel; // This is an extension panel.
-
- err = GXSetupDialogPanel(&panelSetupRec);
-
-
- HaveCollectionMgrError:
-
- return err;
- }
-
-
- /*******************************************************************
- GetJobCollectionItem is a generic routine that retrieves a
- collection item from the job collection.
-
- ********************************************************************/
-
- OSErr GetJobCollectionItem(void *collectItem, long *collectSize,
- OSType collectType, short collectID)
- {
- return GetCollectionItem(GXGetJobCollection(GXGetJob()),
- collectType,
- collectID,
- collectSize,
- collectItem);
- }
-